package com.xiaoxx.controller.es;


import com.xiaoxx.annotation.LogRecords;
import com.xiaoxx.common.base.ESVo;
import com.xiaoxx.common.result.R;
import com.xiaoxx.model.vo.es.CodeXzqhVo;
import com.xiaoxx.service.CodeXzqh2023Service;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author HX
 * @since 2024-03-19
 */
@RestController
@RequestMapping("/api/es")
@Api(value = "CodeXzqh2023Controller", tags = "行政区划")
public class CodeXzqh2023Controller {
    @Autowired
    CodeXzqh2023Service codeGenerationService;

    @ApiOperation("通过level获取行政区划")
    @RequestMapping(value = "/getInfoByLevel", method = RequestMethod.GET)
    @LogRecords(moduleName = "ES模块", content = "通过level获取行政区划")
    public R<List<CodeXzqhVo>> getInfoByLevel(@RequestParam(required = false) String name,
                                              @RequestParam Integer level) throws IOException {
        return R.success(codeGenerationService.getInfoByLevel(name, level));
    }

    @ApiOperation("通过code获取行政区划")
    @RequestMapping(value = "/getInfoByCode", method = RequestMethod.GET)
    @LogRecords(moduleName = "ES模块", content = "通过code获取行政区划")
    public R<ESVo> getInfoByCode(@RequestParam String code,
                                 @RequestParam Integer level,
                                 @RequestParam Integer from,
                                 @RequestParam Integer size) throws IOException {
        return R.success(codeGenerationService.getInfoByCode(code, level, from, size));
    }

    @ApiOperation("通过name获取级行政区划")
    @LogRecords(moduleName = "ES模块", content = "通过name获取级行政区划")
    @RequestMapping(value = "/getInfoByName", method = RequestMethod.GET)
    public R<ESVo> getInfoByName(
            @RequestParam(required = false) String code,
            @RequestParam String name,
            @RequestParam Integer from,
            @RequestParam Integer size) throws IOException {
        return R.success(codeGenerationService.getChildInfoByCode(code,name, from, size));
    }
}

